import errorHandler from "errorhandler";
import express from "express";

const rp = require("request-promise");
import jar from "../api/toughCookie";

const app = express();

app.set("port", process.env.PORT || 3004);
/**
 * Error Handler. Provides full stack - remove for production
 */
app.use(errorHandler());

const api = [
  {
    method: "POST",
    body: JSON.stringify({
      email: "986171791@qq.com"
    }),
    url: "http://api.zqd.com/emailCode/send"
  },
  {
    method: "GET",
    qs: {},
    url: "http://api.zqd.com/emailCode/send"
  }
];

/**
 * Start Express server.
 */
const server = app.listen(app.get("port"), "0.0.0.0", () => {
  console.log(
    "  App is running at http://localhost:%d in %s mode",
    app.get("port"),
    app.get("env")
  );
  console.log("  Press CTRL-C to stop\n");

  console.log("-----------test api start-----------");
  init();
});

async function init() {
  for (const item of api) {
    console.log(item, 999999);
  }
  //   const newurl = "http://api.zqd.com/emailCode/send";
  //   const ret = await rp({
  //     method: "POST",
  //     url: newurl,
  //     body: JSON.stringify({
  //       email
  //     })
  //   }).pipe(res);
  //   const jsonRet = JSON.parse(ret);
  //   res.json(jsonRet);
}

export default server;
